bitkeeper revision 1.319.1.2 (3f0c49b9kvjGDv1bC1QhQNwfEHw9kw)
authorrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>
Wed, 9 Jul 2003 16:58:33 +0000 (16:58 +0000)
committerrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>
Wed, 9 Jul 2003 16:58:33 +0000 (16:58 +0000)
Port of web-based virtual disk manager complete.

17 files changed:
tools/control/src/org/xenoserver/web/RootBean.java
tools/control/web/tmpl/vd-fv.tmpl
tools/control/web/tmpl/vd-pa.tmpl
tools/control/web/tmpl/vd-par.tmpl
tools/control/web/tmpl/vd-pv.tmpl
tools/control/web/tmpl/vd-vbdc.tmpl
tools/control/web/tmpl/vd-vbdcr.tmpl
tools/control/web/tmpl/vd-vbdf.tmpl
tools/control/web/tmpl/vd-vbdfr.tmpl
tools/control/web/tmpl/vd-vbdv.tmpl
tools/control/web/tmpl/vd-vdcr.tmpl
tools/control/web/tmpl/vd-vdd.tmpl
tools/control/web/tmpl/vd-vddr.tmpl
tools/control/web/tmpl/vd-vdr.tmpl
tools/control/web/tmpl/vd-vdrr.tmpl
tools/control/web/tmpl/vd-vdv.tmpl
tools/control/web/tmpl/xenohead.def

index cf65a8f0e1986cb0a3afd7254bcbf63cfea34891..858ee9e3adcc01dcb808957cfb1b3946c9799471 100644 (file)
@@ -14,10 +14,6 @@ import org.xenoserver.control.VirtualDiskManager;
 import org.xenoserver.control.XML;
 
 public class RootBean implements HttpSessionBindingListener {
-    static String state_filename_out = "/var/lib/xen/vdstate.xml";
-    static String partition_filename = "/proc/partitions";
-    static int default_sector_size = 512;
-
     PartitionManager pm;
     VirtualDiskManager vdm;
 
@@ -34,140 +30,15 @@ public class RootBean implements HttpSessionBindingListener {
     public void valueUnbound(HttpSessionBindingEvent event) {
         doFlushState();
     }
-
-/*
-    public int getPartitionCount() {
-        return pm.getPartitionCount();
-    }
-
-    public Partition getPartition(int index) {
-        return pm.getPartition(index);
-    }
-
-    public String doAddPartition(String partition, String chunksize) {
-        Partition p = pm.get_partition(partition);
-        String result = "done";
-        int loop;
-        long size;
-
-        if (p == null) {
-            return (" eh? what partition: " + partition);
-        }
-
-        size = Library.parse_size(chunksize) / default_sector_size;
-        if (size == 0) {
-            return ("error: invalid chunk size");
-        }
-        vdm.add_xeno_partition(p, size);
-        pm.add_xeno_partition(p);
-
-        return "done";
-    }
-
-    public int getVirtualDiskCount() {
-        return vdm.getVirtualDiskCount();
-    }
-
-    public VirtualDisk getVirtualDisk(int index) {
-        return vdm.getVirtualDisk(index);
-    }
-
-    public VirtualDisk getVirtualDiskKey(String key) {
-        return vdm.get_virtual_disk_key(key);
+    
+    public PartitionManager pm() {
+        return pm;
     }
-
-    public String doCreateVirtualDisk(String name, String size, long expiry) {
-        VirtualDisk vd;
-        Date date = new Date();
-        long parse_size;
-
-        parse_size = Library.parse_size(size) / default_sector_size;
-        if (parse_size == 0) {
-            return ("error: invalid size");
-        }
-        vd =
-            vdm.create_virtual_disk(
-                name,
-                parse_size,
-                new Date(date.getTime() + expiry));
-
-        return ("Virtual Disk created with key: " + vd.get_key());
-
+    
+    public VirtualDiskManager vdm() {
+        return vdm;
     }
 
-    public String doDeleteVirtualDisk(String key) {
-        if (key == null || key.trim().equals("")) {
-            return ("error: no virtual disk specified");
-        }
-        vdm.delete_virtual_disk(key);
-
-        return ("okay");
-    }
-
-    public String doRefreshVirtualDisk(String key, long expiry) {
-        VirtualDisk vd = vdm.get_virtual_disk_key(key);
-        Date date;
-        String s = "";
-
-        if (vd == null) {
-            return ("disk not found: " + key);
-        }
-        s = vd.get_expiry().toString();
-        date = new Date(vd.get_expiry().getTime() + expiry);
-        vd.set_expiry(date);
-
-        return ("okay " + expiry + " " + s + " " + date.toString());
-    }
-
-    public int getFreeExtentCount() {
-        VirtualDisk free = vdm.getFreeVirtualDisk();
-        return free.getExtentCount();
-    }
-
-    public Extent getFreeExtent(int index) {
-        VirtualDisk free = vdm.getFreeVirtualDisk();
-        return free.getExtent(index);
-    }
-
-    public Enumeration getVirtualBlockDevices() {
-        return vdm.getVirtualBlockDevices();
-    }
-
-    public String doCreateVirtualBlockDevice(
-        String vd_key,
-        int domain,
-        int vbd_num,
-        String mode) {
-        VirtualBlockDevice vbd;
-        VirtualDisk vd;
-
-        vbd = vdm.create_virtual_block_device(vd_key, domain, vbd_num, mode);
-        if (vbd != null) {
-            String command;
-            FileWriter fw;
-
-            vd = vdm.get_virtual_disk_key(vd_key);
-            command = vd.dump_xen(vbd);
-
-            try {
-                fw = new FileWriter("/proc/xeno/dom0/vhd");
-                fw.write(command);
-                fw.flush();
-                fw.close();
-            } catch (Exception e) {
-                return (e.toString());
-            }
-            return command;
-        } else {
-            return "Error encountered";
-        }
-    }
-
-    public String doFlushVirtualBlockDevices() {
-        vdm.flush_virtual_block_devices();
-        return "done";
-    }
-*/
     public void doFlushState() {
         XML.saveState(pm, vdm, Settings.STATE_OUTPUT_FILE);
     }
index e8b41a2bb52a51cac026c87bca52d5636ec71fdc..fa9ee1f83863e1117402cb8e9157a06e3f4f036a 100644 (file)
@@ -10,25 +10,32 @@ BREADCRUMB&Virtual Disk Manager&vd.jsp
 INCLUDE&vdmenu.tmpl
 <td valign="top">
 
+<%
+  VirtualDisk free = root.vdm().getFreeDisk();  
+%>
 
 <table cellpadding="0" cellspacing="0" border="0">
 <tbody>
 
+<tr><td>
+Total available free space: <%= Library.formatSize(free.getSize() * Settings.SECTOR_SIZE,8,true) %>
+</td></tr>
+
+
+##WHITESPACE## ##GREYLINE1## ##WHITESPACE##
+
 <tr><td>
 <table cellpadding="2" cellspacing="0" border="0">
 <tbody>
-  <tr class="vdh"><td>idx</td><td>disk</td><td>offset</td><td>size </td></tr>
+  <tr class="vdh"><td>disk</td><td>offset</td><td>size </td></tr>
 
   <%
-    long space = 0;
-    int count = root.getFreeExtentCount();
-    for (int loop = 0; loop < count; loop++)
+    Iterator i = free.extents();
+    while (i.hasNext())
     {
-      Extent e = root.getFreeExtent(loop);
-      space += e.getSize();
+      Extent e = (Extent) i.next();
   %>
   <tr class="vdt">
-  <td              ><%= loop %></td>
   <td              ><%= e.getDisk() %></td>
   <td align="right"><%= e.getOffset() %> </td>
   <td align="right"><%= e.getSize() %> </td>
@@ -40,13 +47,6 @@ INCLUDE&vdmenu.tmpl
 </table>
 </td></tr>
 
-
-##WHITESPACE## ##GREYLINE1## ##WHITESPACE##
-
-<tr><td>
-Total available freespace: <%= space * 512 / (1024 * 1024) %> MB
-</td></tr>
-
 </tbody>
 </table>
 
index e71a6bf1958af4c25847bf388db7c74ff799645b..9b8ec98c6022f99cccdf04e666be2ebe98457a44 100644 (file)
@@ -20,11 +20,11 @@ INCLUDE&vdmenu.tmpl
 <tbody>
   <tr class="vdh"><td></td><td>maj:min</td><td>blocks</td><td>start sect</td><td>num sects</td><td>name</td></tr>
   <%
-    int count = root.getPartitionCount();
+    int count = root.pm().getPartitionCount();
     for (int loop = 0; loop < count; loop++)
     {
-       Partition p = root.getPartition(loop);
-       if (p.getIsXeno() == true)
+       Partition p = root.pm().getPartition(loop);
+       if (p.isXeno() == true)
         {
   %>
   <tr class="vds"><td></td>
index b72e99b814d4bbec6f663d4fa500f95099d68b37..a88602441a87682919837e30e24e35fdeb7d2172 100644 (file)
@@ -40,7 +40,7 @@ Error: chunk size not specified.<br>
     {
 %>
 output[<%= i %>] =<br>
-<%= root.doAddPartition(partitions[i], size) %> <br>
+<%= new CommandPartitionAdd(partitions[i], Library.parseSize(size), false).execute() %> <br>
 <%
     }
   }
index 8195f82964e3f019ff094a897e3bb5e57b55aa75..4647f337a5fd45698983f0dc393f8368955c89e3 100644 (file)
@@ -16,11 +16,11 @@ note: highlighted entries are currently being used as xeno partitions.
 <tbody>
   <tr class="vdh"><td>maj:min</td><td>blocks</td><td>start sect</td><td>num sects</td><td>name</td></tr>
   <%
-    int count = root.getPartitionCount();
+    int count = root.pm().getPartitionCount();
     for (int loop = 0; loop < count; loop++)
     {
-      Partition p = root.getPartition(loop);
-      if (p.getIsXeno() == true)
+      Partition p = root.pm().getPartition(loop);
+      if (p.isXeno() == true)
       {
   %>
   <tr class="vds">
index e6952182b8baa7c56ccf7656410c91d216d84770..f6b560badc380f16ce90b144731d17fc21a2410b 100644 (file)
@@ -16,25 +16,25 @@ INCLUDE&vdmenu.tmpl
 <tr><td>
 <table cellpadding="2" cellspacing="0" border="0">
 <tbody>
-  <tr class="vdh"><td></td><td>vd key</td><td width="5"></td><td>name</td><td width="5"></td><td>expiry</td></tr>
+  <tr class="vdh"><td></td><td>vd key</td><td width="5"></td><td>name</td><td width="5"></td><td>expiry</td><td width="5"></td><td>size</td></tr>
 
   <%
-    int count = root.getVirtualDiskCount();
-    for (int loop = 0; loop < count; loop++)
+    Iterator i = root.vdm().getVirtualDisks();
+    while (i.hasNext())
     {
-      VirtualDisk vd = root.getVirtualDisk(loop);
+      VirtualDisk vd = (VirtualDisk) i.next();
   %>
     <tr class="vdt">
       <td>
-        <input type="radio" name="vd" 
-               <% if (loop == 0) { %> checked <% } %>
-               value="<%= vd.getKey() %>">
+        <input type="radio" name="vd" value="<%= vd.getKey() %>">
       </td>
       <td><%= vd.getKey() %></td>
       <td></td>
       <td><%= vd.getName() %></td>
       <td></td>
       <td><%= vd.getExpiry() %></td>
+      <td></td>
+      <td><%= Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,false) %></td>
     </tr>
   <%
     }
index 656be575fcc7f17efe06787d9d91f722154b17af..05bd41992b8db9b0383555fc52f536010f0c9653 100644 (file)
@@ -46,11 +46,18 @@ Error: No virtual block device number specified.<br>
     {
       domain = Integer.decode(hsrw.getParameter("domain")).intValue();
       vbd = Integer.decode(hsrw.getParameter("vbd")).intValue();
+      Mode mode;
+      if (hsrw.getParameter("mode").equals("rw")) {
+        mode = Mode.READ_WRITE;
+      } else {
+        mode = Mode.READ_ONLY;
+      }
+      
 %>
 output =<br>
-<%= root.doCreateVirtualBlockDevice(hsrw.getParameter("vd"),
+<%= new CommandVbdCreate(hsrw.getParameter("vd"),
                                     domain, vbd,
-                                     hsrw.getParameter("mode"))  %>
+                                     mode).execute()  %>
 <%
     }
     catch (NumberFormatException e)
index 0dbcc8d93dad208fe2499b87d36866340a00f80c..eb46b158d6230ae3f8cbf3b8905728d10814a15e 100644 (file)
@@ -20,14 +20,15 @@ INCLUDE&vdmenu.tmpl
   <tr class="vdh"><td>vd key</td><td>dom</td><td>vbd</td><td>mode</td></tr>
 
   <%
-    for (Enumeration e = root.getVirtualBlockDevices(); e.hasMoreElements();)
+    for (Iterator i = root.vdm().getVirtualBlockDevices(); i.hasNext();)
     {
-      VirtualBlockDevice vbd = (VirtualBlockDevice) e.nextElement();
+      VirtualBlockDevice vbd = (VirtualBlockDevice) i.next();
+      VirtualDisk vd = vbd.getVirtualDisk(); 
   %>
     <tr class="vdt">
-      <td><%= vbd.getKey() %></td>
+      <td><%= vd.getKey() %></td>
       <td><%= vbd.getDomain() %></td>
-      <td><%= vbd.getVBDNum() %></td>
+      <td><%= vbd.getVbdNum() %></td>
       <td><%= vbd.getMode().toString() %></td>
     </tr>
   <%
index 566f4cb0389052f8cbdf444532e7f7980312a385..0d172923bdfa9de0d05e586f5d8e90df2e3d6a52 100644 (file)
@@ -17,7 +17,7 @@ INCLUDE&vdmenu.tmpl
 <%
   HttpServletRequestWrapper hsrw = new HttpServletRequestWrapper(request);
 %>
-output = <%= root.doFlushVirtualBlockDevices()  %>
+output = <%= new CommandVbdFlush().execute()  %>
 <%
   root.doFlushState();
 %>
index 306372e2bb5939a4cc3af52af23eaf071e53e360..6a0a03947c6633a2157b357e51d9d6d4c567326a 100644 (file)
@@ -16,16 +16,16 @@ INCLUDE&vdmenu.tmpl
 
 
   <%
-    for (Enumeration e = root.getVirtualBlockDevices(); e.hasMoreElements();)
+    for (Iterator i = root.vdm().getVirtualBlockDevices(); i.hasNext();)
     {
-      VirtualBlockDevice vbd = (VirtualBlockDevice) e.nextElement();
-      VirtualDisk vd = root.getVirtualDiskKey(vbd.getKey()); 
+      VirtualBlockDevice vbd = (VirtualBlockDevice) i.next();
+      VirtualDisk vd = vbd.getVirtualDisk(); 
   %>
     <tr class="vdt">
       <td><%= vbd.getDomain() %></td>
-      <td><%= vbd.getVBDNum() %></td>
+      <td><%= vbd.getVbdNum() %></td>
       <td><%= vbd.getMode().toString() %></td>
-      <td><%= vbd.getKey() %></td>
+      <td><%= vd.getKey() %></td>
       <td><%= vd.getName() %></td>
     </tr>
   <%
index 08e63b2e9059e420c3707946e61d3a9f4e7c0bb7..9550407a1b8629e7c0a736312af7bac0d4614085 100644 (file)
@@ -60,9 +60,11 @@ Error: expiry time not specified.<br>
       {
         expiry *= 24 * 60 * 60 * 1000 * 365;
       }
+      
+      expiry += System.currentTimeMillis();
 %>
 output =<br>
-<%= root.doCreateVirtualDisk( hsrw.getParameter("name"), size, expiry) %>
+<%= new CommandVdCreate( hsrw.getParameter("name"), Library.parseSize(size), new Date(expiry)).execute() %>
 <br>
 <%
     }
index 920899b1b2b6dca291ef77a5a58157eed2f9289a..3b50e1450cf22ccf90776e9bbe1b6d70ef568fa7 100644 (file)
@@ -16,13 +16,13 @@ INCLUDE&vdmenu.tmpl
 <tr><td>
 <table cellpadding="2" cellspacing="0" border="0">
 <tbody>
-  <tr class="vdh"><td></td><td>key</td><td width="5"></td><td>name</td><td width="5"></td><td>expiry</td></tr>
+  <tr class="vdh"><td></td><td>key</td><td width="5"></td><td>name</td><td width="5"></td><td>expiry</td><td width="5"></td><td>size</td></tr>
 
   <%
-    int count = root.getVirtualDiskCount();
-    for (int loop = 0; loop < count; loop++)
+    Iterator i = root.vdm().getVirtualDisks();
+    while (i.hasNext())
     {
-      VirtualDisk vd = root.getVirtualDisk(loop);
+      VirtualDisk vd = (VirtualDisk) i.next();
   %>
     <tr class="vdt">
       <td><input type="checkbox" name="vd" value="<%= vd.getKey() %>"></td>
@@ -31,6 +31,8 @@ INCLUDE&vdmenu.tmpl
       <td><%= vd.getName() %></td>
       <td></td>
       <td><%= vd.getExpiry() %></td>
+      <td></td>
+      <td><%= Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,false) %></td>
     </tr>
   <%
     }
index 13925ebb8b409b7f861e2da5fc6b0e10566aa089..355c111e816f3ef6c2c8b054fb1776810790d124 100644 (file)
@@ -18,7 +18,7 @@ INCLUDE&vdmenu.tmpl
 
 vd= <%= hsrw.getParameter("vd") %>
 
-vd= <%= root.doDeleteVirtualDisk(hsrw.getParameter("vd")) %>
+vd= <%= new CommandVdDelete(hsrw.getParameter("vd")).execute() %>
 
 <%
   root.doFlushState();
index 551d230cebc2ac82d48a08cc58e392b4dc408706..df9c20abf633cf2bf259da4119d0acf0e90fe35e 100644 (file)
@@ -16,13 +16,13 @@ INCLUDE&vdmenu.tmpl
 <tr><td>
 <table cellpadding="2" cellspacing="0" border="0">
 <tbody>
-  <tr class="vdh"><td></td><td>key</td><td width="5"></td><td>name</td><td width="5"></td><td>expiry</td></tr>
+  <tr class="vdh"><td></td><td>key</td><td width="5"></td><td>name</td><td width="5"></td><td>expiry</td><td width="5"></td><td>size</td></tr>
 
   <%
-    int count = root.getVirtualDiskCount();
-    for (int loop = 0; loop < count; loop++)
+    Iterator i = root.vdm().getVirtualDisks();
+    while (i.hasNext())
     {
-      VirtualDisk vd = root.getVirtualDisk(loop);
+      VirtualDisk vd = (VirtualDisk) i.next();
   %>
     <tr class="vdt">
       <td><input type="checkbox" name="vd" value="<%= vd.getKey() %>"></td>
@@ -31,6 +31,8 @@ INCLUDE&vdmenu.tmpl
       <td><%= vd.getName() %></td>
       <td></td>
       <td><%= vd.getExpiry() %></td>
+      <td></td>
+      <td><%= Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,false) %></td>
     </tr>
   <%
     }
index 068b2830565c3c4c3aca2e2d8d75c9694cf75614..bca0dccf8730bfe095bbe4e8d7b6b55b8006eb0c 100644 (file)
@@ -51,10 +51,12 @@ Error: expiry time not specified.<br>
       expiry *= 24 * 60 * 60 * 1000 * 365;
     }
 
+       expiry += System.currentTimeMillis();
+       
     for (int i = 0; i < vds.length; i++)
     {
 %>
-vd = <%= root.doRefreshVirtualDisk(vds[i], expiry) %> <br>
+vd = <%= new CommandVdRefresh(vds[i], new Date(expiry)).execute() %> <br>
 <%
     }
   }
index e03cd6959f41e26f48e48ec4a7390f0a21458bea..78a6f9b7740aba76ebe0caec6d525f91ade66b72 100644 (file)
@@ -12,13 +12,13 @@ INCLUDE&vdmenu.tmpl
 
 <table cellpadding="2" cellspacing="0" border="0">
 <tbody>
-  <tr class="vdh"><td>key</td><td width="5"></td><td>name</td><td width="5"></td><td>expiry</td></tr>
+  <tr class="vdh"><td>key</td><td width="5"></td><td>name</td><td width="5"></td><td>expiry</td><td width="5"></td><td>size</td></tr>
 
   <%
-    int count = root.getVirtualDiskCount();
-    for (int loop = 0; loop < count; loop++)
+    Iterator i = root.vdm().getVirtualDisks();
+    while (i.hasNext())
     {
-      VirtualDisk vd = root.getVirtualDisk(loop);
+      VirtualDisk vd = (VirtualDisk) i.next();
   %>
     <tr class="vdt">
       <td><%= vd.getKey() %></td>
@@ -26,6 +26,8 @@ INCLUDE&vdmenu.tmpl
       <td><%= vd.getName() %></td>
       <td></td>
       <td><%= vd.getExpiry() %></td>
+      <td></td>
+      <td><%= Library.formatSize(vd.getSize()*Settings.SECTOR_SIZE,8,false) %></td>
     </tr>
   <%
     }
index 5b0934a0510ee5d6d52078f804abcadd6f9095e3..12b957a1dfb61e0460c77481edda977f89df758d 100644 (file)
@@ -8,6 +8,7 @@
 <%@ page import="org.xenoserver.web.*" %>
 <%@ page import="org.xenoserver.control.*" %>
 <%@ page import="java.util.Iterator" %>
+<%@ page import="java.util.Date" %>
 <%@ page import="javax.servlet.http.HttpServletRequestWrapper" %>
 
 <html lang="en">